/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jeff.springWebTestNG.util;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author winnie
 */
public class MyBeanUtil {
    private static final Logger LOG = Logger.getLogger(MyBeanUtil.class.getName());
    
    public static List<String> scanClassesByPackage(String packageToScan) {
        List<String> classes = new ArrayList<String>();
        
        String packageToScanIO = packageToScan.replace('.', '/');
        URL packageUrl = Thread.currentThread().getContextClassLoader().getResource(packageToScanIO);
        LOG.log(Level.FINE, "package: {0}", packageUrl.getFile());
        File packagePath = new File(packageUrl.getFile());
        for (File classFile : packagePath.listFiles()) {
            String classShortName = classFile.getName();
            classShortName = classShortName.substring(0, classShortName.lastIndexOf("."));
            String fullClassName = packageToScan + "." + classShortName;
            LOG.log(Level.FINE, "*** {0}", new Object[]{fullClassName});
            
            classes.add(fullClassName);
        }
        
        return classes;
    }
}
